package com.kiln.juxingqs.adapter

import androidx.recyclerview.widget.DiffUtil
import client.global.commlib.base.BasePagingAdapter
import client.global.commlib.base.PagingViewHoder
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.GetDddBatchRet
import com.kiln.juxingqs.databinding.LayoutPagingbathTihuoItemBinding

class GetPagingBathTihuoRetAdapter :
    BasePagingAdapter<GetDddBatchRet.Batch>(object : DiffUtil.ItemCallback<GetDddBatchRet.Batch>() {
        override fun areItemsTheSame(
            oldItem: GetDddBatchRet.Batch,
            newItem: GetDddBatchRet.Batch
        ): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(
            oldItem: GetDddBatchRet.Batch,
            newItem: GetDddBatchRet.Batch
        ): Boolean {
            return oldItem == newItem
        }
    }) {

    var ok: ((b: GetDddBatchRet.Batch) -> Unit)? = null

    fun okClick(b: GetDddBatchRet.Batch) {
        ok?.invoke(
            b
        )
    }

    override fun bindItem(holder: PagingViewHoder, t: Any) {
        val binding = holder.binding as LayoutPagingbathTihuoItemBinding
        val bean = t as GetDddBatchRet.Batch
        binding.bean = bean
        binding.event = this
        val time = bean.create_time.substring(
            5,
            bean.create_time.length - 3

        )
        binding.time = time

        if (!bean.status_str.isNullOrEmpty()) {
            binding.type = bean.status_str
        }
        /*else
        when (bean.d_type) {
            0 -> {
                binding.type = "交易票"
            }
            1 -> {
                binding.type = "冻结票"
            }
            2 -> {
                binding.type = "释放票"
            }
            }*/
    }

    override fun getItemLayout(): Int {
        return R.layout.layout_pagingbath_tihuo_item
    }
}